<script setup lang="ts">
import { ref, watch } from "vue";

const iconBgLeft = ref<52 | 164 | 275>(52);
const iconBgBR = ref<string>("50%");

const iconBlackLeft = ref(59);
const iconBlackBR = ref("50%");

const active = ref("home");

watch(active, () => {
  switch (active.value) {
    case "home":
      iconBgLeft.value = 52;
      iconBgBR.value = "50%";

      iconBlackLeft.value = 59;
      iconBlackBR.value = "50%";
      break;
    case "search":
      iconBgLeft.value = 164;
      iconBgBR.value = "8px";

      iconBlackLeft.value = 170;
      iconBlackBR.value = "8px";
      break;
    case "user":
      iconBgLeft.value = 275;
      iconBgBR.value = "50%";

      iconBlackLeft.value = 282;
      iconBlackBR.value = "50%";
      break;
    default:
      break;
  }
});
</script>

<template>
  <div class="water_box">
    <div class="tab-bg">
      <div class="tab_bg_blur"></div>
      <div
        class="icon_bg"
        :style="{
          left: iconBgLeft + 'px',
          borderRadius: iconBgBR,
        }"
      >
        <div></div>
      </div>
    </div>
    <div class="img_icon">
      <img
        src="/image/home.svg"
        alt="icon"
        @click="active = 'home'"
        :style="{ transform: `translateY(${active === 'home' ? -24 : 0}px)` }"
      />
      <img
        src="/image/search.svg"
        alt="icon"
        @click="active = 'search'"
        :style="{ transform: `translateY(${active === 'search' ? -24 : 0}px)` }"
      />
      <img
        src="/image/user.svg"
        alt="icon"
        @click="active = 'user'"
        :style="{ transform: `translateY(${active === 'user' ? -24 : 0}px)` }"
      />
      <div
        class="icon_black"
        :style="{
          left: iconBlackLeft + 'px',
          borderRadius: iconBlackBR,
        }"
      ></div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.water_box {
  width: 375px;
  height: 820px;
  background-color: #f7f7f7;
  position: relative;

  .tab-bg {
    width: 100%;
    height: 54px;
    position: absolute;
    left: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 1);
    filter: contrast(17);
    overflow: hidden;

    .tab_bg_blur {
      width: 100%;
      height: 100%;
      background-color: #333;
      position: absolute;
      left: 0;
      top: 0;
      filter: blur(6px);
      z-index: 1;
    }

    .icon_bg {
      width: 48px;
      height: 48px;
      background-color: #f7f7f7;
      border-radius: 50%;
      position: absolute;
      top: -24px;
      left: 52px;
      filter: blur(6px);
      z-index: 1;
      transition: all 0.3s;
    }
  }

  .img_icon {
    width: 100%;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 64px;
    padding-right: 64px;
    z-index: 2;
    position: absolute;
    bottom: 0;
    left: 0;

    img {
      width: 24px;
      height: 24px;
      z-index: 10;
      cursor: pointer;
      transition: all 0.3s;
    }

    .icon_black {
      width: 34px;
      height: 34px;
      background-color: #333;
      border-radius: 50%;
      position: absolute;
      top: -14px;
      left: 59px;
      transition: all 0.3s;
      filter: contrast(17);
    }
  }
}
</style>
